package com.itcoon.demo.web.controller.serialize;/**
 * @author Athric Yu
 * 2024/11/11
 **/

import com.itcoon.cloud.framework.transform.Transformer;
import com.itcoon.cloud.framework.webmvc.response.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 *
 *
 * @author Athric Yu
 * 2024/11/11
 **/
@Tag(name = "序列化，反序列化")
@RequestMapping("/serials")
@RestController
public class SerializeController {

    @Operation(summary = "测试路径枚举参数")
    @GetMapping("/query/{gender}")
    @Parameter(name="gender", schema = @Schema(description = "性别"))
    public ApiResponse<Gender> path(@PathVariable Gender gender){
        return ApiResponse.ok(gender);
    }

    @Operation(summary = "测试query枚举参数")
    @GetMapping("")
    @Parameter(name="gender", schema = @Schema(description = "性别"))
    public ApiResponse<Gender> query(@RequestParam Gender gender){
        return ApiResponse.ok(gender);
    }

    @Operation(summary = "测试query对象枚举参数")
    @GetMapping("/search")
    public ApiResponse<SearchRespVO> search(@Validated SearchReqVO searchReqVO){
        return ApiResponse.ok(Transformer.<SearchReqVO, SearchRespVO>to(SearchRespVO.class).apply(searchReqVO).convert());
    }

    @Operation(summary = "JSON Body 枚举")
    @PostMapping
    public ApiResponse<SearchRespVO> create(@RequestBody @Validated SearchReqVO searchReqVO){
        return ApiResponse.ok(Transformer.<SearchReqVO, SearchRespVO>to(SearchRespVO.class).apply(searchReqVO).convert());
    }
}
